#ifndef __VSF_FATFS_H_INCLUDED__
#define __VSF_FATFS_H_INCLUDED__

#include "component/3rd/fatfs/source/diskio.h"
#include "component/3rd/fatfs/source/ff.h"

struct vsf_fatfs_entry_t
{
	union
	{
		FIL *f;
		DIR *d;
		void *ptr;
	};
};

struct vsf_fatfs_file_t
{
	struct vsfile_t file;
	struct vsf_fatfs_entry_t entry;
};

struct vsf_fatfs_t
{
	struct vsfmal_t *mal;
	struct vsfsm_thread_t thread;
	uint8_t stack[1024];

	struct vsfsm_crit_t crit;
	struct vsfsm_t *pending_sm;
	DIR root;
	union
	{
		struct
		{
			DIR *dir;
			char *name;
			struct vsf_fatfs_file_t *file;
		} getchild;
		struct
		{
			struct vsf_fatfs_file_t *file;
		} close;
		struct
		{
			uint64_t offset;
			uint32_t size;
			uint32_t rw_size;
			uint8_t *buff;
			struct vsf_fatfs_file_t *file;
		} rw;
	};
};

// to use vsf_fatfs_fsop, enable configurations in ffconf.h
//		FF_FS_RPATH MUST be set to 1
//		FF_USE_LFN MUST be enabled
//		if FF_FS_REENTRANT is enabled
//			FF_SYNC_t MUST be set to struct vsfsm_crit_t *
//			include "vsf.h"
extern const struct vsfile_fsop_t vsf_fatfs_fsop;

int vsf_fatfs_add_disk(struct vsfmal_t *mal);
void vsf_fatfs_remove_disk(struct vsfmal_t *mal);

#endif		// __VSF_FATFS_H_INCLUDED__
